package com.ngmaster.socket.main;

import com.ngmaster.apiserver.config.SocketConfig;
import com.ngmaster.socket.MessageManager;
import com.ngmaster.socket.TcpServer;
import com.ngmaster.socket.util.NumberUtil;

public class Server {


    public Server() {
        super();
    }

    public void run(int listenPort) {

        if (listenPort == 0) {
            return;
        }

        // 注册消息处理类
        MessageManager.getInstance().init(new SocketConfig());

        // 启动socket服务
        TcpServer tcpServer = new TcpServer();
        tcpServer.init(listenPort);

    }

    public static void main(String[] args) {
        Server server = new Server();
        int port = NumberUtil.stringToNumber(System.getProperty("listenPort"), 10000);
        server.run(port);
        System.out.println("服务器启动成功，监听socket端口：" + port);
    }
}
